import 'package:ac/common/style.dart';
import 'package:ac/model/ac_blocked_model.dart';
import 'package:ac/widget/ac_app_bar.dart';
import 'package:ac/widget/ac_no_data_widget.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'ac_blocked_list_logic.dart';

class AcBlockedListPage extends StatelessWidget {
  final logic = Get.find<AcBlockedListLogic>();
  final state = Get.find<AcBlockedListLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AcAppbar(title: "Block List"),
      body: _buildBody(),
    );
  }

  _buildBody() {
    return Obx(() {
      if(state.blockList.isEmpty){
        return const AcNoDataWidget();
      }
      return Container(
        color: Colors.white,
        child: ListView.builder(
          padding: EdgeInsets.only(top: 12.h),
          itemBuilder: (context, index) {
            return _buildItem(index);
          },
          itemCount: state.blockList.length,
        ),
      );
    });
  }

  _buildItem(int index) {
    AcBlockedModel model = state.blockList[index];
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.h),
      child: Row(
        children: [
          ClipOval(
            child: CachedNetworkImage(
              imageUrl: model.avatar,
              width: 44.w,
              height: 44.w,
            ),
          ),
          SizedBox(width: 10.w),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  model.nickName,
                  maxLines: 1,
                  style: TextStyle(fontSize: 16.sp, color: textColorBlack),
                ),
                SizedBox(height: 10.h),
                Text(
                  "${model.age} ${model.registerCountry}",
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: Colors.black.withOpacity(0.4),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(width: 18.w),
          GestureDetector(
            onTap: () {
              logic.unblockUser(model.broadcasterId);
            },
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(25.w),
                color: const Color(0xff454545),
              ),
              height: 26.sp,
              width: 71.w,
              alignment: Alignment.center,
              child: Text(
                "Unblock",
                style: TextStyle(fontSize: 12.sp, color: Colors.white),
              ),
            ),
          )
        ],
      ),
    );
  }
}
